<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  <title>物流仓库信息表</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
  <script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
	 <script type="text/javascript" src="plug-in/jquery/jquerysession.js"></script>
  <script type="text/javascript">

      $(document).ready(function () {
          $.ajax({
              type:"GET",
              url:"cbsWarehouseController.do?getLogistics",
              dataType:"json",
              success:function (data) {
                  var name = $("#logists").val();
                  var tbs = data.obj;
                  var  htmll = "<option>--请选择--</option>";
                  for (i in tbs){
                      if (tbs[i].departname==name){
                          htmll += '<option  value='+tbs[i].departname+' selected="selected">'+tbs[i].departname+'</option>';
                      }else {
                          htmll += '<option  value='+tbs[i].departname+'>'+tbs[i].departname+'</option>';
                      }
                  }
                  $("#logistics").html(htmll);

              }
          })
          $.ajax({
              type:"GET",
              url:"cbsWarehouseController.do?getProvince",
              dataType:"json",
              success:function (data) {
                  var name = $("#shengName").val();
                  var tbs = data.obj;
                  var  htmll = "<option>--请选择--</option>";
                  for (i in tbs){
                      if (tbs[i].id==name){
                          htmll += '<option  value='+tbs[i].territoryCode+' selected="selected">'+tbs[i].territoryName+'</option>';
					  }else {
                          htmll += '<option  value='+tbs[i].territoryCode+'>'+tbs[i].territoryName+'</option>';
					  }

                  }
                  $("#sheng").html(htmll);

              }
          })
          var province = $("#sheng").val();
          $.ajax({
              type:"GET",
              data:{"code":province},
              url:"cbsWarehouseController.do?getCity",
              dataType:"json",
              success:function (data) {
                  var tbs = data.obj;
                  var  html = "";
                  var cityName = $("#cityName").val();
                  for (i in tbs){
                      if (tbs[i].id==cityName){
                          html += "<option value="+tbs[i].id+" selected='selected'>"+tbs[i].territoryName+"</option>";
                      }else {
                          html += "<option value="+tbs[i].id+">"+tbs[i].territoryName+"</option>";
                      }

                  }
                  $("#city").html(html);

              }
          })
      })
      function getCity() {
          var province = $("#sheng").val();
          $.ajax({
              type:"GET",
              data:{"code":province},
              url:"cbsWarehouseController.do?getCity",
              dataType:"json",
              success:function (data) {
                  var tbs = data.obj;
                  var  html = "";
                  var cityName = $("#cityName").val();
                  for (i in tbs){
                      if (tbs[i].id==cityName){
                          html += "<option value="+tbs[i].id+" selected='selected'>"+tbs[i].territoryName+"</option>";
					  }else {
                          html += "<option value="+tbs[i].id+">"+tbs[i].territoryName+"</option>";
					  }

                  }
                  $("#city").html(html);

              }
          })
      }
      function reTurn() {
          setTimeout("  addOneTab(\"物流仓库管理\",'cbsWarehouseController.do?cbsWarehouse');",1000);
      }
      function updateWare() {
          var cityId = $("#cityId").val();
          var cityId2 = $("#cityId2").val();
          var cityId3  = $("#cityId3").val();
          var cityId4  = $("#cityId4").val();
          var slaOneId = $("#slaOneId").val();
          var slaTwoId = $("#slaTwoId").val();
          var slaThreeId  = $("#slaThreeId").val();
          var slaFourId  = $("#slaFourId").val();
          var t1 = $("#t1").html();
          if (typeof(t1)=="undefined" ){
              var sl1 = getSL1Span();
              t1=sl1;
          }
          var t2 = $("#t2").html();
          if (typeof(t2)=="undefined" ){
              var sl2 = getSL2Span();
              t2=sl2;
          }
          var t3 = $("#t3").html();
          if (typeof(t3)=="undefined" ){
              var sl3 = getSL3Span();
              t3=sl3;
          }
          var t4 = $("#t4").html();
          if (typeof(t4)=="undefined" ){
              var sl4 = getSL4Span();
              t4=sl4;
          }
          var id = $("#id").val();
          var name = $("#name").val();
          var code = $("#code").val();
          var userName = $("#userName").val();
          var phone = $("#phone").val();
          var email = $("#email").val();
          if (name==code){
              jQuery.messager.confirm('提示:','同一物流仓库名称和代码不能重复',function(event){});
              return false;
          }
          var logistics = $("#logistics").val();
          var province = $("#sheng").val();
          var city = $("#city").val();
          var address = $("#address").val();
          lockmask(true);
		  $.ajax({
              type:"POST",
              data:{"id":id,"name":name,"code":code,"logistics":logistics,"province":province,"city":city
			  ,"cityId":cityId,"cityId2":cityId2,"cityId3":cityId3,"cityId4":cityId4,
			  "slaOneId":slaOneId,"slaTwoId":slaTwoId,"slaThreeId":slaThreeId,"slaFourId":slaFourId,
                  "t1":t1,"t2":t2,"t3":t3,"t4":t4,"userName":userName,"phone":phone,"email":email
			  ,"address":address},
              url:"cbsWarehouseController.do?doUpdate",
              dataType:"json",
              success:function (data) {
                  lockmask(false);
                          tip("修改成功");
                  setTimeout("  addOneTab(\"物流仓库管理\",'cbsWarehouseController.do?cbsWarehouse');",1000);
                  setTimeout("closetab('修改')",1000);
              }
		  })
      }
      function choose() {
          var cityId = $("#SL1").text();
          var logistics = $("#logistics").val();
          var name = $("#name").val();
          $.session.set("ids",cityId);
          $.dialog({
              content: "url:cbsWarehouseController.do?goChooseCity&logistics="+logistics+"&name="+name+"",
              zIndex: 2100,
              title: '选择城市',
              lock: true,
              width: '800px',
              height: '500px',
              left: '85%',
              top: '65%',
              opacity: 0.4,
              init: function () {
                  top.myWindow = window;
              },
              button: [{
                  name: '确认',
                  callback: function () {
                      var iframe = this.iframe.contentWindow;
                      var cid =  iframe.$("#oneValue").val();
                      var cname =  iframe.$("#oneText").val();
                      if( typeof(cid)!="undefined" && typeof (cname)!="undefined"){
                          var SL2=  $("#t2").text();
                          var SL3=  $("#t3").text();
                          var SL4=  $("#t4").text();
                          var   b = arrRepeat(cname,SL2,SL4,SL3);
                          if (b){
                              alert("一个物流一个仓库与一个目的地城市只能有一条对应关系");
                              return false;
                          }else {
                              $("#SL1").html("<span id='t1'>"+cname+"</span>");
                              $("#cityId").val(cid);
                          }
                      }else {
                          $("#SL1").html("<span id='t1'></span>");
                          $("#cityId").val("");
                          $("#slaOneId").val("");
                      }
                      $.session.remove('city_id');
                      $.session.remove('city_name');
                      $.session.clear();
				  },
                  focus: true
              }, {
                  name: '返回',
                  callback: function () {
                  }
              }]
          });
      }
      function choose2() {
          var cityId = $("#SL2").text();
          var logistics = $("#logistics").val();
          var name = $("#name").val();
          $.session.set("ids",cityId);
          $.dialog({
              content: "url:cbsWarehouseController.do?goChooseCity2&logistics="+logistics+"&name="+name+"",
              zIndex: 2100,
              title: '选择城市',
              lock: true,
              width: '800px',
              height: '500px',
              left: '85%',
              top: '65%',
              opacity: 0.4,
              init: function () {
                  top.myWindow = window;
              },
              button: [{
                  name: '确认',
                  callback: function () {
                      var iframe = this.iframe.contentWindow;
                      var cid =  iframe.$("#twoValue").val();
                      var cname =  iframe.$("#twoText").val();
                      if( typeof(cid)!="undefined" && typeof (cname)!="undefined"){
                          var SL1=  $("#t1").text();
                          var SL3=  $("#t3").text();
                          var SL4=  $("#t4").text();

                          var   b = arrRepeat(cname,SL1,SL4,SL3);
                          if(b){
                              alert("一个物流一个仓库与一个目的地城市只能有一条对应关系");
                              return false;
                          }else{
                              $("#SL2").html("<span id='t2'>"+cname+"</span>");
                              $("#cityId2").val(cid);
                          }
                      }else{
                          $("#SL2").html("<span id='t1'></span>");
                          $("#cityId2").val("");
                          $("#slaTwoId").val("");
                      }
                      $.session.clear();

                  },
                  focus: true
              }, {
                  name: '返回',
                  callback: function () {
                  }
              }]
          });
      }
      function choose4() {
          var cityId = $("#SL4").text();
          var logistics = $("#logistics").val();
          var name = $("#name").val();
          $.session.set("ids",cityId);
          $.dialog({
              content: "url:cbsWarehouseController.do?goChooseCity4&logistics="+logistics+"&name="+name+"",
              zIndex: 2100,
              title: '选择城市',
              lock: true,
              width: '800px',
              height: '500px',
              left: '85%',
              top: '65%',
              opacity: 0.4,
              init: function () {
                  top.myWindow = window;
              },
              button: [{
                  name: '确认',
                  callback: function () {
                      var iframe = this.iframe.contentWindow;
                      var cid =  iframe.$("#fourValue").val();
                      var cname =  iframe.$("#fourText").val();
                      if( typeof(cid)!="undefined" && typeof (cname)!="undefined"){
                          var SL2=  $("#t2").text();
                          var SL3=  $("#t3").text();
                          var SL1=  $("#t1").text();
                          var   b = arrRepeat(cname,SL2,SL1,SL3);
                          if(b){
                              alert("一个物流一个仓库与一个目的地城市只能有一条对应关系");
                              return false;
                          }else{
                              $("#SL4").html("<span id='t4'>"+cname+"</span>");
                              $("#cityId4").val(cid);
                              $("#slaFourId").val("");
                          }

                      }else {
                          $("#SL4").html("<span id='t4'></span>");
                          $("#cityId4").val("");
                      }
                      $.session.remove('city_id');
                      $.session.remove('city_name');
                      $.session.clear();
                  },
                  focus: true
              }, {
                  name: '返回',
                  callback: function () {
                  }
              }]
          });
      }
      function choose3() {
          var cityId = $("#SL3").text();
          var logistics = $("#logistics").val();
          var name = $("#name").val();
          $.session.set("ids",cityId);
          $.dialog({
              content: "url:cbsWarehouseController.do?goChooseCity3&logistics="+logistics+"&name="+name+"",
              zIndex: 2100,
              title: '选择城市',
              lock: true,
              width: '800px',
              height: '500px',
              left: '85%',
              top: '65%',
              opacity: 0.4,
              init: function () {
                  top.myWindow = window;
              },
              button: [{
                  name: '确认',
                  callback: function () {
                      var iframe = this.iframe.contentWindow;
                      var cid =  iframe.$("#threeValue").val();
                      var cname =  iframe.$("#threeText").val();
                      if( typeof(cid)!="undefined" && typeof (cname)!="undefined"){
                          var SL2=  $("#t2").text();
                          var SL4=  $("#t4").text();
                          var SL1=  $("#t1").text();
                          var   b = arrRepeat(cname,SL2,SL1,SL4);
                          if(b){
                              alert("一个物流一个仓库与一个目的地城市只能有一条对应关系");
                              return false;
                          }else{
                              $("#SL3").html("<span id='t3'>"+cname+"</span>");
                              $("#cityId3").val(cid);
                          }
                      }else {
                          $("#SL3").html("<span id='t3'></span>");
                          $("#cityId3").val("");
                          $("#slaThreeId").val("");
                      }
                      $.session.clear();
                  },
                  focus: true
              }, {
                  name: '返回',
                  callback: function () {
                  }
              }]
          });
      }
      function closeWare() {
          var id = $("#id").val();
          $.dialog({
              content: "url:cbsWarehouseController.do?goCloseWare",
              zIndex: 2100,
              title: '填写备注',
              lock: true,
              width: '800px',
              height: '500px',
              left: '85%',
              top: '65%',
              opacity: 0.4,
              init: function () {
                  top.myWindow = window;
              },
              button: [{
                  name: '确认',
                  callback: function () {
                      var remarks = $.session.get("remarks");
                      $.ajax({
                          type:"post",
                          dataType:"json",
                          data:{"remarks":remarks,"id":id},
                          url:"cbsWarehouseController.do?closeWare",
                          success:function (data) {
                              var attr = data.attributes;
                              if (attr.sta==1){
                                  setTimeout("  addOneTab(\"物流仓库管理\",'cbsWarehouseController.do?cbsWarehouse')");
                              }
                          }
                      })
                  },
                  focus: true
              }, {
                  name: '返回',
                  callback: function () {
                  }
              }]
          });
      }
      var xmlhttp;
      function createXmlhttp(){
          if(window.XMLHttpRequest){
              xmlhttp = new XMLHttpRequest();
          }
          else if(window.ActiveXObject){
              try{
                  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
              }catch(e){
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
              }
          }
          return xmlhttp;

      }
      function ClearSession()
      {
          createXmlhttp();
          var url="Service.asmx/ClearSession";
          xmlhttp.open("POST",url,true);
          xmlhttp.onreadystatechange=handleStateChange;
          xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
          xmlhttp.send(queryString);
      }
      function handleStateChange()
      {
          if(xmlhttp.readyState==4)
          {
              if(xmlhttp.status==200)
              {
                  console.log("清除成功");
              }
          }
      }
      function getSL1Span() {
          var html = "";
          $("#SL1 span").each(function () {
              var value = $(this).html();
              html+=" "+value;
          })
          return html;
      }
      function getSL2Span() {
          var html = "";
          $("#SL2 span").each(function () {
              var value = $(this).html();
              html+=" "+value;
          })
          return html;
      }
      function getSL3Span() {
          var html = "";
          $("#SL3 span").each(function () {
              var value = $(this).html();
              html+=" "+value;
          })
          return html;
      }
      function getSL4Span() {
          var html = "";
          $("#SL4 span").each(function () {
              var value = $(this).html();
              html+=" "+value;
          })
          return html;
      }
      function arrRepeat(cname,s,t,t2) {
          var citys="";
          citys = citys.concat(cname,s,t,t2);
          var ary = citys.split(" ");
          var nary = ary.sort();

          var hash = {};
          for(var i in nary) {
              if(hash[nary[i]])
                  return true;
              hash[nary[i]] = true;
          }
          return false;
      }
  </script>
 </head>
 <body>
  <%--<t:formvalid formid="formobj" dialog="true" usePlugin="password" layout="table" action="cbsWarehouseController.do?doUpdate" tiptype="1">--%>
					<input id="id" name="id" type="hidden" value="${cbsWarehousePage.id }">
					<input id="createName" name="createName" type="hidden" value="${cbsWarehousePage.createName }">
					<input id="createBy" name="createBy" type="hidden" value="${cbsWarehousePage.createBy }">
					<input id="createDate" name="createDate" type="hidden" value="${cbsWarehousePage.createDate }">
					<input id="updateName" name="updateName" type="hidden" value="${cbsWarehousePage.updateName }">
					<input id="updateBy" name="updateBy" type="hidden" value="${cbsWarehousePage.updateBy }">
					<input id="updateDate" name="updateDate" type="hidden" value="${cbsWarehousePage.updateDate }">
  <div style="margin-bottom:10px;">
	  <img style="margin-bottom:-7px" src="../plug-in/login/images/dispatch bill.png">
	  <div style="position: absolute; text-align: center; width: 100%; margin-top:-20px;">
		  <a href="#" class="easyui-linkbutton l-btn" onclick="updateWare()">提交</a>
		  <a href="#" class="easyui-linkbutton l-btn" onclick="reTurn()">返回</a>
		  <a href="#" class="easyui-linkbutton l-btn" onclick="closeWare()">关闭仓库</a>
	  </div>
  </div>

  <div class="subtitle">
	  <p>基本信息</p>
	  <table class="nobordertable noborder">
		  <tbody>
		  <tr>
			  <td class="al_r" width="20%">
				  <label>仓库名称:</label>
			  </td>
			  <td width="30%">
				  <input id="name" name="name" type="text" style="width: 150px" class="inputxt"
						 value='${cbsWarehousePage.name}'>
			  </td>
			  <td class="al_r" width="20%">
				  <label>物流:</label>
			  </td>
			  <td width="30%">
				  <select id="logistics">
					  <%--<option <c:if test="${cbsWarehousePage.logistics eq '配思'}">selected</c:if>>配思</option>--%>
					  <%--<option <c:if test="${cbsWarehousePage.logistics eq '乔达'}">selected</c:if>>乔达</option>--%>
				  </select>
			  </td>
		  </tr>
		  <tr>
			  <td class="al_r" width="20%">
				  <label>仓库代码:</label>
			  </td>
			  <td width="30%">
				  <input id="code" name="code" value='${cbsWarehousePage.code}'/>
				  <input id="shengName" value='${cbsWarehousePage.sheng.id}' type="hidden"/>
				  <input id="cityName" value='${cbsWarehousePage.shi.id}' type="hidden"/>
				  <input id="logists" value='${cbsWarehousePage.logistics }' type="hidden"/>
			  </td>
			  <td class="al_r" width="20%">
				  <label>仓库所在地:</label>
			  </td>
			  <td width="30%">
				  <select style="width: auto;" id="sheng" name="sheng.id" onchange="getCity()">
					  <%--<option>--请选择--</option>--%>
				  </select>
				  <select style="width: auto;" name="shi.id" id="city" >
					  <option>--请选择--</option>
				  </select>
			  </td>

		  </tr>
		  <tr>
			  <td class="al_r" width="20%">
				  <label>联系人姓名:</label>
			  </td>
			  <td width="30%">
				  <input id="userName" name="userName" type="text" style="width: 150px" class="inputxt"
						 value='${cbsWarehousePage.userName}'>
			  </td>
			  <td class="al_r" width="20%"><label>详细地址:</label></td>
			  <td width="30%"><input style="width:80%" id="address" name="address" value='${cbsWarehousePage.address}' >

		  </tr>
		  <tr>
			  <td class="al_r" width="20%">
				  <label>联系人电话:</label>
			  </td>
			  <td width="30%">
				  <input id="phone" name="phone" type="text" style="width: 150px" class="inputxt"
						 value='${cbsWarehousePage.phone}'>
			  </td>
			  <td class="al_r" width="20%">
				  <label>联系人邮箱:</label>
			  </td>
			  <td width="30%">
				  <input id="email" name="email" type="text" style="width: 200px" class="inputxt"
						 value='${cbsWarehousePage.email}'>
			  </td>
		  </tr>
		  </tbody>
	  </table>
	  <div style="margin-top:10px;">
		  SL1目的地城市:<a href="#" class="easyui-linkbutton l-btn" onclick="choose()">选择</a>
		  <div class="l-div" id="SL1" style="height: auto">
			  <%--<c:forEach items="${slaOne}" var="one">--%>
				  <span id="t1">${slaOne}</span>
			  <%--</c:forEach>--%>
		  </div>
		  <input type="hidden" id="cityId">
		  <input type="hidden" id="slaOneId" value="${slaOneId}"/>
	  </div>
	  <div style="margin-top:10px;" >
		  SL2目的地城市:<a href="#" class="easyui-linkbutton l-btn" onclick="choose2()">选择</a>
		  <div class="l-div" id="SL2" style="height: auto">
			  <%--<c:forEach items="${slaTwo}" var="two">--%>
				  <span id="t2">${slaTwo}</span>
			  <%--</c:forEach>--%>
		  </div>
		  <input type="hidden" id="cityId2">
		  <input type="hidden" id="slaTwoId" value="${slaTwoId}"/>
	  </div>
	  <div style="margin-top:10px;" >
		  SL3目的地城市:<a href="#" class="easyui-linkbutton l-btn" onclick="choose3()">选择</a>
		  <div class="l-div" id="SL3" style="height: auto">
			  <%--<c:forEach items="${slaThree}" var="three">--%>
				  <span id="t3">${slaThree}</span>
			  <%--</c:forEach>--%>
		  </div>
		  <input type="hidden" id="cityId3">
		  <input type="hidden" id="slaThreeId" value="${slaThreeId}"/>
	  </div>
	  <div style="margin-top:10px;" >
		  SL4目的地城市:<a href="#" class="easyui-linkbutton l-btn" onclick="choose4()">选择</a>
		  <div class="l-div" id="SL4" style="height: auto">
			  <%--<c:forEach items="${slaFour}" var="four">--%>
				  <span id="t4">${slaFour}</span>
			  <%--</c:forEach>--%>
		  </div>
		  <input type="hidden" id="cityId4">
		  <input type="hidden" id="slaFourId" value="${slaFourId}"/>
	  </div>
  </div>
		<%--</t:formvalid>--%>
 </body>
  <script src = "webpage/com/zybk/cbswarehouse/cbsWarehouse.js"></script>